/*
 * This source code is part of TWaver 4.0
 *
 * Serva Software PROPRIETARY/CONFIDENTIAL. Use is subject to license terms.
 * Copyright 2002 - 2011 Serva Software. All rights reserved.
 */

package demo.chart.gdp;

import java.awt.Color;
import java.awt.event.MouseEvent;
import java.awt.event.MouseMotionAdapter;

import javax.swing.JLabel;

import twaver.Element;
import twaver.TWaverConst;
import twaver.chart.AbstractChart;

public class MouseListener extends MouseMotionAdapter{
	
	private AbstractChart chart = null;
	
	public MouseListener(AbstractChart chart){
		this.chart = chart;
		JLabel label = chart.getTitleLabel();
		label.setOpaque(true);
		label.setForeground(Color.WHITE);
		this.chart.getChartPane().addMouseMotionListener(this);
	}
	
    public void mouseMoved(MouseEvent e) {
    	Element element = chart.getElementAt(e.getPoint());
    	if(element != null){
    		String value = TWaverConst.DEFAULT_INT_FORMATER.format(element.getChartValue());
    		JLabel label = chart.getTitleLabel();
    		label.setText(element.getName() + ":" + value + "$");
    		label.setBackground(element.getChartColor());
    		chart.getDataBox().getSelectionModel().setSelection(element);
    	}
    }
}